# 作者: 陈其志
# 2025年02月17日23时38分18秒
# 2716847110@qq.com


def use_while():
    i = 1
    while i <= 5:
        print(i)
        i += 1
    print(f"i的值是{i}")


def sum_100():
    i = 1
    result = 0
    while i <= 100:
        result += i
        i += 1
    print(f"1到100的和是{result}")


def sum_2000_break():
    i = 1
    result = 0
    while i <= 100:
        if result > 2000:
            break
        result += i
        i += 1

    print(f"i的值是{i}, result的值是{result}")


def use_for():
    """
    for in后面必须是可迭代对象
    :return:
    """
    my_list = [1, 2, 3, 4, 5]
    for i in my_list:
        # print本身就输出了一个换行，想要不换行，后面加入end = ''就是
        print(i, end=' ')

    for i in range(10):  # range(10)意思是左闭右开
        if i == 15:
            print(f'I have 15')
        else:
            print(f'I have {i}')


def use_for_else():
    """
    for else中的else是for中没有break，就一定会走else
    :return:
    """
    for i in range(10):  # range(10)意思是左闭右开
        if i == 15:
            print(f'I have 15')
            break   # break意思是跳出循环,不会执行else
    else:
        print(f'don`t find 15')


# use_while()
# sum_100()
# sum_2000_break()
# use_for()
use_for_else()